﻿using System.Web.Mvc;
using Common;
using Models;
using Web.Areas.Admin.Lib;
using Web.Lib;
using System;

namespace Web.Areas.Admin.Controllers
{
    public class HomeController : BaseController
    {
        public ActionResult Index()
        {
            if (Account.ID > 0)
            {
                var user = new admin_accountLogic().Getadmin_account(Account.ID);
                return View(user);
            }
            else
            {
                return Redirect("/admin/account/logon");
            }
        }

        public ActionResult Profile()
        {
            var user = new admin_accountLogic().Getadmin_account(Account.ID);

            return View(user);
        }

        public ActionResult ScoreSetting()
        {
            scoresettingLogic sl = new scoresettingLogic();
            var dbSeeting = sl.Getscoresetting(new scoresetting());
            if (dbSeeting == null)
            {
                scoresetting setting = new scoresetting()
                {
                    createdate = DateTime.Now,
                    createuserid = Account.ID,
                    isdeleted = false,
                    isexcludeminandmax = false,
                    expertpercent = 50
                };
                var id = sl.Create(setting);
                setting.id = id;
                return View(setting);
            }
            else
            {
                return View(dbSeeting);
            }
        }

        [HttpPost]
        public ActionResult ScoreSetting(scoresetting setting)
        {
            try
            {
                scoresettingLogic sl = new scoresettingLogic();
                setting.modifydate = DateTime.Now;
                setting.modifyuserid = Account.ID;
                var result = sl.Update(setting);
                if (result)
                {
                    return SuccessMsg("保存成功！");
                }
                else
                {
                    return ErrorMsg("保存失败，网络错误！");
                }
            }
            catch (Exception e)
            {
                return ErrorMsg(e.Message);
            }

        }
    }
}
